﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Icms.Core.Model;
using Icms.Core.Repository;
using Icms.Resources;

namespace Icms.WebUI.Controllers
{
    public class HearingIdAjaxDropdownController : Controller
    {
        private readonly IRepo<Hearing> r;

        public HearingIdAjaxDropdownController(IRepo<Hearing> r)
        {
            this.r = r;
        }

        public ActionResult GetItems(Guid? key, Guid parent)
        {
            var list = new List<SelectListItem> { new SelectListItem { Text = Mui.not_selected, Value = "" } };

            var res = r.Where(o => o.CaseId == parent);

            list.AddRange(res.Select(o => new SelectListItem
                                              {
                                                  Text = o.Type.Title,
                                                  Value = o.Id.ToString(),
                                                  Selected = o.Id == key
                                              }));
            return Json(list);
        }
    }
}